package at.tasat.assignment;

import at.tasat.cnf.Literal;

public final class Assignment {
	private final int variableId;
	private final boolean phase;

	public Assignment(int variableId, boolean phase) {
		assert variableId > 0;
		this.variableId = variableId;
		this.phase = phase;
	}

	public int getVariableId() {
		return variableId;
	}

	public boolean getPhase() {
		return phase;
	}

	public boolean isTrue(int literal) {
		assert Literal.getVariableId(literal) == variableId;
		return Literal.isTrue(literal, phase);
	}

	@Override
	public boolean equals(Object obj) {
		if (obj instanceof Assignment) {
			Assignment other = (Assignment) obj;
			return variableId == other.variableId && phase == other.phase;
		}
		return false;
	}

	@Override
	public int hashCode() {
		return variableId;
	}

	@Override
	public String toString() {
		return variableId + " -> " + phase;
	}
}
